package StudyCode.summary.textfile;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GetLineBeginningWithFile {
	public static void main(String[] argv) throws Exception {
		File file = new File("E:/Copy/test1.txt");
		String value = "www.tah1986.com";
		System.out.println(getLineBeginningWith(file, value));
	}

	public static String getLineBeginningWith(File file, String value) {
		try {
			BufferedReader reader = new BufferedReader(new FileReader(file));

			String line;
			while ((line = reader.readLine()) != null) {
				if (line.startsWith(value)) {
					break;
				}
			}

			reader.close();
			return (line != null) ? line : "";
		} catch (IOException ex) {
			ex.printStackTrace();
			return "";
		}
	}
}
